import { request, upload,requestStream } from './request';

export const uploadChatFile = async (tempFilePath, fileName = '') => {
  const resp = await upload(
    '/system/messages/uploadFile',
    tempFilePath,
    'file',
    fileName
  );
  return resp;
};

export const createConversation = async params => {
  const resp = await request('/system/conversations', 'POST', params);
  return resp;
};

export const sendMsg = async params => {
  const resp = await request('/system/messages', 'POST', params);
  return resp;
};

export const sendMsgStream = async (params, onMessage, onError, onComplete, onReference) => {
  const resp = await requestStream('/system/messages/sse', 'POST', params, onMessage, onError, onComplete, onReference);
  return resp;
};

export const conversationList = async (pageNum = 1, pageSize = 20) => {
  const resp = await request('/system/conversations/list', 'GET', {
    isAsc: 'desc',
    orderByColumn: 'id',
    pageNum,
    pageSize,
  });
  return resp;
};

export const getChatDetailById = async id => {
  const resp = await request(
    `/system/messages/list?conversationId=${id}`,
    'GET'
  );
  return resp;
};

export const getUnreadCount = async () => {
  const resp = await request('/system/conversations/getUnreadCount', 'GET');
  return resp;
};

export const updateConversation = async params => {
  const resp = await request('/system/conversations', 'PUT', params);
  return resp;
};
